import java.util.ArrayList;


public class CheckersBoard
{
   private static int PLAYER1 = 1;
   private static int PLAYER2 = 2;
   
   private static int LIMIT = 8;
   
   private Board board;
   
   public CheckersBoard()
   {
      board = new Board(LIMIT);
      
      //init all pieces
      int even,odd;
      Piece p;
      for(even=0, odd=1;even<LIMIT;even+=2, odd+=2)
      {
         p = new Piece(new Position(7, even), PLAYER1);
         board.putPiece(p);
         
         p = new Piece(new Position(5 ,even), PLAYER1);
         board.putPiece(p);
         
         p = new Piece(new Position(6, odd), PLAYER1);
         board.putPiece(p);
         
         p = new Piece(new Position(0, odd), PLAYER2);
         board.putPiece(p);
         
         p = new Piece(new Position(1, even), PLAYER2);
         board.putPiece(p);
         
         p = new Piece(new Position(2, odd), PLAYER2);
         board.putPiece(p);       
      }   
   }
   public boolean move(Position prev, Position next)
   {
      boolean result = false;
      Piece p = board.getPiece(prev);
      ArrayList<Position> moves;
      if(p != null)
      {
         moves = p.getMoves(board);
         for (Position pos : moves)
         {
            if(next.equals(pos))
            {
               p.setPosition(next);
               result = board.putPiece(p);
               board.removePiece(prev);
               System.out.println("moved");
            }
         }
      }
      return result;
   }
   public String Print()
   {
      return board.printBoard();
   }
   
}
